package structure;


import java.util.*;

public class Test13 extends Sort2 {
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] arr = {100,8,9,4,5,7,84,84,848,9595,100,10,100,10,100,100};
        Sort2.countingSort(arr);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] arr = new int[1_0000];
        reverseOrder(arr);
        testSort1(arr);
        testSort2(arr);
        testSort3(arr);
        testSort4(arr);
        testSort5(arr);
        testSort6(arr);
        testSort7(arr);
        testSort100(arr);
        testSort8(arr);
        testSort9(arr);
        testSort10(arr);
    }
    public static void order(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }

    public static void reverseOrder(int[] array) {
        for (int i = 0; i < array.length; i++) {
            array[i] = array.length-i;
        }
    }

    public static void randomOrder(int[] array) {
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(array.length);
        }
    }
    public static void testSort100(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.quickSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序(优化)耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }
    public static void testSort1(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }

    public static void testSort2(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.shellSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("希尔排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }

    public static void testSort3(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.selectSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }

    public static void testSort4(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.selectSort2(array);
        long endTime = System.currentTimeMillis();
        System.out.println("选择(双指针)排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }

    public static void testSort5(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.heapSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("堆排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }

    public static void testSort6(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.QuickSort(array,0,array.length - 1);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序(挖坑)耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }

    public static void testSort7(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.QuickSort2(array);
        long endTime = System.currentTimeMillis();
        System.out.println("快速排序(非递归-栈)耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }
    public static void testSort8(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.bubbleSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("冒泡排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }
    public static void testSort9(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.countingSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("计数排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }
    public static void testSort10(int[] array) {
        array = Arrays.copyOf(array,array.length);
        long startTime = System.currentTimeMillis();
        Sort2.mergeSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("归并排序耗时："+(endTime-startTime));
        System.out.println(Arrays.toString(array));
    }
}
